package com.flute.haflute.jobbox.base.mapreduce;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import com.flute.haflute.jobbox.base.JobSubmitter;

/**
 * MapReduce应用进行分布式任务执行时，通过该系统入口进行
 * 
 * @author Liu Liu
 * @date 2010-5-4
 */
public class MapReduceDriver {

	/**
	 * 
	 * @param job :
	 *            MRJobConf: MapReduce任务的任务配置文件
	 * @throws MalformedURLException
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public void runJob(MRJobConf job) throws MalformedURLException,
			RemoteException, NotBoundException {
		runJob(job, "localhost", 1099);
	}
	
	/**
	 * 
	 * @param job :
	 *            MRJobConf: MapReduce任务的任务配置文件
	 * @throws MalformedURLException
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public void runJob(MRJobConf job, String masterIp, int rmiport) throws MalformedURLException,
			RemoteException, NotBoundException {
		System.out.println("Begin to submit MR job");

		//获取主节点任务提交的接口，并提交任务
		JobSubmitter jobSubmitter = (JobSubmitter) Naming.lookup("rmi://"
				+ masterIp + ":" + rmiport + "/" + "JOB_SUBMITTER");
		jobSubmitter.submit(job,null);

		System.out.println("Submit finished");
	}
}
